Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add chains crawler for seer. #9

Merged
merged 28 commits into from
May 28, 2024
Merged

Add chains crawler for seer. #9

merged 28 commits into from
May 28, 2024

Conversation

Andrei-Dolgolev
Copy link
Contributor

@Andrei-Dolgolev Andrei-Dolgolev commented Feb 7, 2024

CLI commands:

Usage run crawler

Before running the crawler, you need initialize the database with the following command:

go run *.go index initialize
go run *.go crawler --chain polygon --start-block 53922484 --force --provider-uri

Env variable.

export MOONSTREAM_INDEX_URI="sqlite://<path_to_file>/moonstream.db"
export INFURA_KEY="<infura_api_key>"

Benchmarks:
https://gist.github.com/Andrei-Dolgolev/f34cac8daf626b369d068ac58bec547d

Universal Indexes structure:

type BlockIndex struct {
	BlockNumber    int64
	BlockHash      string
	BlockTimestamp int64
	ParentHash     string
	Filepath       string
}

type TransactionIndex struct {
	BlockNumber          int64
	BlockHash            string
	BlockTimestamp       int64
	TransactionHash      string
	TransactionIndex     int64
	TransactionTimestamp int64
	Filepath             string
}

type LogIndex struct {
	BlockNumber     int64
	BlockHash       string
	BlockTimestamp  int64
	TransactionHash string
	LogIndex        int64
	Filepath        string
}

protobuff structure:

// Represents a single transaction within a block
message SingleTransaction {
  string hash = 1;
  int64 block_number = 2;
  string from_address = 3;
  string to_address = 4;
  string gas = 5; // using string to handle big numeric values
  string gas_price = 6;
  string max_fee_per_gas = 7;
  string max_priority_fee_per_gas = 8;
  string input = 9; // could be a long text
  string nonce = 10;
  int64 transaction_index = 11;
  int32 transaction_type = 12;
  string value = 13; // using string to handle big numeric values
  int64 indexed_at = 14; // using int64 to represent timestamp
  int64 block_timestamp = 15; // using int64 to represent timestam
}

// Represents a single blockchain block
message Block {
  int64 block_number = 1;
  int64 difficulty = 2;
  string extra_data = 3;
  int64 gas_limit = 4;
  int64 gas_used = 5;
  string base_fee_per_gas = 6; // using string to handle big numeric values
  string hash = 7;
  string logs_bloom = 8;
  string miner = 9;
  string nonce = 10;
  string parent_hash = 11;
  string receipt_root = 12;
  string uncles = 13;
  int32 size = 14;
  string state_root = 15;
  int64 timestamp = 16;
  string total_difficulty = 17;
  string transactions_root = 18;
  int64 indexed_at = 19; // using int64 to represent timestamp
  repeated SingleTransaction transactions = 20;
}


message EventLog {
  string address = 1; // The address of the contract that generated the log
  repeated string topics = 2; // Topics are indexed parameters during log generation
  string data = 3; // The data field from the log
  int64 block_number = 4; // The block number where this log was in
  string transaction_hash = 5; // The hash of the transaction that generated this log
  string block_hash = 6; // The hash of the block where this log was in
  bool removed = 7; // True if the log was reverted due to a chain reorganization
  int64 log_index = 8; // The index of the log in the block
  int64 transaction_index = 9; // The index of the transaction in the block
}

Copy link
Contributor

@kompotkot kompotkot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wk

@Andrei-Dolgolev Andrei-Dolgolev merged commit f161415 into main May 28, 2024
1 check passed
@Andrei-Dolgolev Andrei-Dolgolev deleted the add-crawler branch May 28, 2024 14:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants